// The contents of this file are subject to the Mozilla Public License Version
// 1.1
//(the "License"); you may not use this file except in compliance with the
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
//
//Software distributed under the License is distributed on an "AS IS" basis,
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
//for the specific language governing rights and
//limitations under the License.
//
//The Original Code is "The Columba Project"
//
//The Initial Developers of the Original Code are Frederik Dietz and Timo
// Stich.
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
//
//All Rights Reserved.
package org.columba.mail.gui.table.plugins;

import java.awt.Component;

import javax.swing.ImageIcon;
import javax.swing.JTable;
import javax.swing.SwingConstants;

import org.columba.core.resourceloader.ImageLoader;
import org.columba.mail.gui.table.model.MessageNode;
import org.columba.mail.message.ColumbaHeader;
import org.columba.mail.resourceloader.MailImageLoader;
import org.columba.mail.util.MailResourceLoader;
import org.columba.ristretto.message.Flags;

public class StatusRenderer extends DefaultLabelRenderer {

	boolean bool;

	ImageIcon image2;

	ImageIcon image3;

	ImageIcon image5;

	ImageIcon image6;

	ImageIcon image7;

	public StatusRenderer() {
		super();

		setHorizontalAlignment(SwingConstants.CENTER);

		image2 = MailImageLoader.getSmallIcon("message-mail-replied.png");
		image3 = ImageLoader.getSmallIcon("user-trash.png");

		image5 = MailImageLoader.getSmallIcon("message-mail-read.png");
		image6 = MailImageLoader.getSmallIcon("message-mail-unread.png");
		image7 = MailImageLoader.getSmallIcon("edit.png");
	}

	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {
		super.getTableCellRendererComponent(table, value, isSelected, hasFocus,
				row, column);

		if (value == null) {
			setIcon(null);

			return this;
		}

		setText("");

		if (value instanceof String) {
			System.out
					.println("statusrenderer-> instanceof String not expected");

			return this;
		}

		Flags flags = ((ColumbaHeader) ((MessageNode) value).getHeader())
				.getFlags();

		if (flags.getDeleted()) {
			setIcon(image3);

			setToolTipText(MailResourceLoader.getString("header", "column",
					"expunged"));
		} else if (flags.getAnswered()) {
			setIcon(image2);
			setToolTipText(MailResourceLoader.getString("header", "column",
					"answered"));
		} else if (flags.getDraft()) {
			setIcon(image7);
			setToolTipText(MailResourceLoader.getString("header", "column",
					"draft"));
		} else if (!flags.getSeen()) {
			setIcon(image6);
			setToolTipText(MailResourceLoader.getString("header", "column",
					"unread"));
		} else if (flags.getSeen()) {
			setIcon(image5);
			setToolTipText(MailResourceLoader.getString("header", "column",
					"read"));
		} else {
			setIcon(null);
		}

		return this;
	}
}